<template>
  <div class="nav-sticky">
    <div>
      <ul v-if="dataList && dataList.length > 0">
        <li class="flex flex-center position-r"
          v-for="item in dataList" :key="item.sidebarId"
          @mouseenter="mouseStickyEnter(item)" 
          @mouseleave="mouseStickyLeave(item)"
          @click="handleJumpPage(item)">
          <img :src="item.iconPicUrl" alt="" class="width-26 height-26">
          <div v-show="item.hoverType === 2 && item.showHoverContext" class="sticky-left-layer customer">
            <div class="layer-container mar-r-19 flex v-align-c flex-center">
              <span class="font-16">{{item.hoverContext }}</span>
            </div>
          </div>
          <div v-show="item.hoverType === 1 && item.showHoverPicUrl" class="sticky-left-layer qrcode">
            <div class="layer-container mar-r-19">
              <img :src="item.hoverPicUrl" alt="">
            </div>
          </div>
        </li>
      </ul>
      <el-backtop class="backtop" :bottom="143" :right="87">
        <ul>
          <li class="flex flex-center">
            <img :src="iconNavBacktop" alt="" class="width-26 height-26">
          </li>
        </ul>
      </el-backtop>
    </div>
  </div>
</template>

<script lang="ts">
import iconNavCustomer from '@/assets/images/icon_nav_customer.png'
import iconNavBrand from '@/assets/images/icon_nav_brand.png'
import iconNavCart from '@/assets/images/icon_nav_cart.png'
import iconNavCooperate from '@/assets/images/icon_nav_cooperate.png'
import iconNavFeedback from '@/assets/images/icon_nav_feedback.png'
import iconNavQrcode from '@/assets/images/icon_nav_qrcode.png'
import iconNavCompleted from '@/assets/images/icon_nav_completed.png'
import iconNavBacktop from '@/assets/images/icon_nav_backtop.png'
import qrcode from '@/assets/images/uploads/qrcode.png'
import { defineComponent, ref, onMounted } from 'vue'
import { getSidebarList } from '@/api/common/navigationBar'
import { jumpPage } from '@/utils/jumpPageUtils'
import { useRouter } from 'vue-router'
export default defineComponent({
  name: 'RightNavSticky',
  setup() {
    const customerLayer = ref(false)
    const qrcodeLayer = ref(false)
    const dataList =  ref(<any>[])
    onMounted(() => {
      initSidebarList()
    })
    const mouseStickyEnter = (item) => {
      if (item.hoverType === 1) {
        item.showHoverPicUrl = true
        item.showHoverContext = false
      } else if (item.hoverType === 2) {
        item.showHoverPicUrl = false
        item.showHoverContext = true
      }
    }
    const mouseStickyLeave = (item) => {
      if (item.hoverType === 1) {
        item.showHoverPicUrl = false
      } else if (item.hoverType === 2) {
        item.showHoverContext = false
      }
    }
    const initSidebarList = () => {
      getSidebarList().then(response => {
        dataList.value = response.data
      })
    }
    const router = useRouter()
    const handleJumpPage = (item) => {
        jumpPage(router, item.hasLink, item.linkTarget, item.linkType, item.linkParams, item.newPage)
      }

    return {
      iconNavCustomer,
      iconNavBrand,
      iconNavCart,
      iconNavCooperate,
      iconNavFeedback,
      iconNavQrcode,
      iconNavCompleted,
      iconNavBacktop,
      customerLayer,
      qrcodeLayer,
      mouseStickyEnter,
      mouseStickyLeave,
      qrcode,
      dataList,
      handleJumpPage
    }
  }
})
</script>

<style lang="scss" scoped>
  .nav-sticky{
    position: fixed;
    right: 87px;
    top: 283px;
    z-index: 100;
    ul{
      background: #182245;
      li{
        width: 52px;
        height: 56px;
        position: relative;
        cursor: pointer;
        &:after{
          content: '';
          display: block;
          position: absolute;
          width: 40px;
          height: 1px;
          background: #8c91a2;
          left: 6px;
          bottom: 0;
        }
        &:last-child{
          &:after{
            display: none;
          }
        }
        .sticky-left-layer{
          position: absolute;
          right: 52px;
          top: 0;
          z-index: 101;
          &:before{
            content: '';
            display: block;
            width:0;
            height:0;
            border-top: 5px solid transparent;
            border-left: 7px solid #182245;
            border-bottom: 5px solid transparent;
            position: absolute;
            right: 12px;
          }
          &.customer{
            cursor: text;
            &:before{
              content: '';
              display: block;
              top: 50%;
              margin-top: -5px;
            }
            .layer-container{
              background: #182245;
              color: #fff;
              box-shadow: 0px 2px 10px 0px rgba(20, 38, 72, 0.17);
              min-width: 234px;
              height: 56px;
              line-height: 56px;
              text-align: center;
            }
          }
          &.qrcode{
            &:before{
              content: '';
              display: block;
              top: 25px;
            }
            .layer-container{
              background: #182245;
              padding: 4px;
              img{
                width: 130px;
                height: 130px;
              }
            }
          }
        }
      }
    }
    ::v-deep(.el-backtop){
      width: 52px;
      height: 56px;
      border-radius: 0;
      box-shadow: 0 0 0;
      background-color: transparent!important
    }
  }
</style>
